import beans.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

//添加启动类
public class App {
    public static void main(String[] args) {
//        //另一种方式得到 spring 上下文
//        BeanFactory factory =
//                new XmlBeanFactory(new ClassPathResource("spring-config.xnl"));
//
//        User user = factory.getBean("userInfo",User.class);
//        user.SayHi("haha");



        //1.得到 spring 上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");


        //2.根据上下文提供的方法获取到 bean
//        User user = (User) context.getBean("userInfo");
        //3.使用 bean 对象
//        user.SayHi("tanchen");


        //====更过获取 bean 的方法=======
//        User user = context.getBean(User.class);如果将同一个类型注册了多次，那这个方法就不行了，因为不知道到底是哪个bean对象
//        user.SayHi("tanchen1");


        User user = context.getBean("userInfo",User.class);
        user.SayHi("tanchen2");
    }
}
